package com.manager.plat.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.manager.plat.vo.UserInfoVo;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class UserInterceptor extends AbstractInterceptor {
	private static Logger logger = Logger.getLogger(UserInterceptor.class);
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext actionContext = invocation.getInvocationContext();
		HttpServletRequest request = (HttpServletRequest) actionContext.get(ServletActionContext.HTTP_REQUEST);
		HttpSession session = request.getSession();
		
		UserInfoVo user = (UserInfoVo) session.getAttribute("user");
		if(user != null){
			request.setAttribute("user", user);
			return invocation.invoke();
		}
		request.setAttribute("errMsg", "缓存超时,请重新登录!");
		return "error";
	}
}